package com.beidu.lottery.call.controller;


import com.alibaba.fastjson.JSONObject;
import com.beidu.lottery.call.entity.form.InfoSaveStep1Form;
import com.beidu.lottery.call.entity.form.InfoSaveStep2Form;
import com.beidu.lottery.call.entity.query.ActivityListQuery;
import com.beidu.lottery.call.entity.vo.ActivityInfoListVO;
import com.beidu.lottery.call.entity.vo.ActivityInfoStep1VO;
import com.beidu.lottery.call.entity.vo.ActivityInfoStep2VO;
import com.beidu.lottery.call.result.Res;
import com.beidu.lottery.call.service.portal.ActivityBaseInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 活动基础信息表 前端控制器
 * </p>
 */
@Slf4j
@RestController
@RequestMapping("/activity")
public class ActivityBaseInfoController {

    @Autowired
    private ActivityBaseInfoService service;

    @ApiOperation(value = "查询活动列表(分页)", notes = "")
    @PostMapping("/list")
    public Res queryActivityList(@RequestBody ActivityListQuery query) {
        log.info("[ActivityBaseInfoController queryActivityList] param:{}!", JSONObject.toJSONString(query));
        PageInfo<ActivityInfoListVO> pageInfo = service.queryActivityList(query);
        log.info("[ActivityBaseInfoController queryActivityList] result:{}!", JSONObject.toJSONString(pageInfo));
        return new Res().data(pageInfo);
    }


    @ApiOperation(value = "保存活动基本信息", notes = "")
    @PostMapping("/saveStep1")
    public Res saveStep1(@RequestBody InfoSaveStep1Form form) {
        log.info("[ActivityBaseInfoController saveStep1] param:{}!", JSONObject.toJSONString(form));
        Integer integer = service.saveBaseInfoStep1(form);
        log.info("[ActivityBaseInfoController saveStep1] result:{}!", JSONObject.toJSONString(integer));
        return new Res().data(integer);
    }

    @ApiOperation(value = "查询活动基础信息", notes = "")
    @GetMapping("/detailStep1")
    public Res detailStep1(@RequestParam("activityId") Integer activityId) {
        log.info("[ActivityBaseInfoController detailStep1] param:{}!", JSONObject.toJSONString(activityId));
        ActivityInfoStep1VO infoStep1VO = service.queryInfoStep1(activityId);
        log.info("[ActivityBaseInfoController detailStep1] result:{}!", JSONObject.toJSONString(infoStep1VO));
        return new Res().data(infoStep1VO);
    }

    @ApiOperation(value = "保存活动规则相关", notes = "")
    @PostMapping("/saveStep2")
    public Res saveStep2(@RequestBody InfoSaveStep2Form form) {
        log.info("[ActivityBaseInfoController saveStep2] param:{}!", JSONObject.toJSONString(form));
        service.saveBaseInfoStep2(form);
        log.info("[ActivityBaseInfoController saveStep2] success!");
        return Res.success();
    }

    @ApiOperation(value = "查询活动规则相关", notes = "")
    @GetMapping("/detailStep2")
    public Res detailStep2(@RequestParam("activityId") Integer activityId) {
        log.info("[ActivityBaseInfoController detailStep2] param:{}!", JSONObject.toJSONString(activityId));
        ActivityInfoStep2VO infoStep2VO = service.queryInfoStep2(activityId);
        log.info("[ActivityBaseInfoController detailStep2] result:{}!", JSONObject.toJSONString(infoStep2VO));
        return new Res().data(infoStep2VO);
    }

}

